home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / FlyThrough 1.1.2 / src / Source / Grayscale Classes / CBevelAttachment.cp < prev    next >
Encoding:
Text File  |  1997-03-19  |  3.3 KB  |  130 lines  |  [TEXT/CWIE]

  1. //
  2. //    CBevelAttachment.cp
  3. //
  4. //    A Constructor-aware, PowerPlant Attachment for adding 
  5. //    an Apple Grayscale Appearance-like bevel to an LView.
  6. //
  7. //    Copyright ©1996 by James Jennings. All rights reserved.
  8. //    September 1, 1996
  9. //
  10.  
  11. #include "CBevelAttachment.h"
  12.  
  13. CGABaseAttachment::CGABaseAttachment( LStream *inStream )
  14.     : LAttachment( inStream ) 
  15. {    // we don't let Constructor specify any other kind of message
  16.     mMessage = msg_DrawOrPrint;
  17. }
  18.  
  19. void    CGABaseAttachment::ExecuteSelf( MessageT inMessage, void *ioParam)
  20. {    // Call the correct draw routine depending on the screen depth.
  21. #pragma unused(inMessage)
  22.     
  23.     Assert_( ioParam != nil );
  24.     
  25.     StColorState theSavedState;
  26.     
  27.     Rect theFrame = *(Rect *)ioParam;
  28.     
  29.     // The device loop sets the clip rect, so we need to tell it 
  30.     // the rect we plan to draw to.
  31.     Rect clipRect = theFrame;
  32.     AdjustClipRect( clipRect );
  33.     
  34.     StDeviceLoop devices(clipRect);
  35.     Int16 depth;
  36.  
  37.     while (devices.NextDepth(depth)) {
  38.         StColorPenState savePenState;        // Will save and restore pen state
  39.         savePenState.Normalize();
  40.         
  41.         if (depth > 3) {
  42.             DrawColor( theFrame );    // we have at least 16 colors
  43.         } else {
  44.             DrawBlackAndWhite( theFrame );
  45.         }
  46.     }
  47.  
  48. }
  49.  
  50. #pragma mark === CBevelAttachment ===
  51. // a general attachement that can be entered in Constructor and then Reanimated
  52. CBevelAttachment * CBevelAttachment::CreateFromStream( LStream *inStream )
  53. {
  54.     return new CBevelAttachment( inStream );
  55. }
  56.  
  57. CBevelAttachment::CBevelAttachment( LStream *inStream )
  58.     : CGABaseAttachment(inStream)
  59. {
  60.     inStream->ReadData( &mBevelIn, sizeof( mBevelIn ) );
  61.     inStream->ReadData( &mWidth, sizeof( mWidth ) );
  62.     inStream->ReadData( &mErase, sizeof( mErase ) );
  63. }
  64.  
  65. CBevelAttachment::CBevelAttachment( Boolean inBevelIn, Int16 inWidth, Boolean inErase )
  66.     : mBevelIn( inBevelIn ), mWidth( inWidth ), mErase(inErase)
  67. {
  68. }
  69.  
  70. void    CBevelAttachment::DrawColor( Rect inFrame )
  71. {
  72.     if (mErase) {
  73.         SetBackColor(ga_White);
  74.         ::EraseRect(&inFrame);
  75.     }
  76.     
  77.     EGAColor tl, br, corners;    // topleft, bottomright, and corner colors
  78.     if ( mBevelIn ) {
  79.         tl = ga_Shadow;
  80.         br = ga_Hilite;
  81.         corners = ga_Shadow;
  82.     } else {
  83.         tl = ga_Hilite;
  84.         br = ga_Shadow;
  85.         corners = ga_Hilite;
  86.     }
  87.     
  88.     Int16 count;
  89.     if (mWidth<0) {
  90.         count = -mWidth;
  91.         ::InsetRect( &inFrame, mWidth, mWidth );
  92.     } else {
  93.         count = mWidth;
  94.     }
  95.     
  96.     for ( Int16 i=0; i<count; i++ ) {
  97.         FrameRect( inFrame, tl, br, corners );
  98.         ::InsetRect( &inFrame, 1, 1 );
  99.     
  100.     }
  101. //    PaintRect( r, ga_Background );
  102. }
  103.  
  104. #pragma mark === other attachments ===
  105.  
  106. void    CGAPaneAttachment::DrawColor( Rect inFrame )
  107. {
  108.     FrameRect( inFrame, ga_Hilite, ga_Shadow, ga_Hilite );
  109.     ::InsetRect( &inFrame, 1, 1 );
  110.     PaintRect( inFrame, ga_Background );
  111. }
  112.  
  113. void    CGADeepPaneAttachment::DrawColor( Rect inFrame )
  114. {    // The color scheme of a movable modal dialog. (Not counting the black outline.)
  115.     FrameRect( inFrame, ga_2, ga_10, ga_2 );
  116.     ::InsetRect( &inFrame, 1, 1 );
  117.     FrameRect( inFrame, ga_White, ga_6, ga_2 );
  118.     ::InsetRect( &inFrame, 1, 1 );
  119.     PaintRect( inFrame, ga_Background );
  120. }
  121.  
  122. void    CGATextFieldAttachment::DrawColor( Rect inFrame )
  123. {    // Note: Since we are drawing outside the panes boundaries, it is possible
  124.     // that the edge will not get redrawn if the update region includes the bevel
  125.     // but not the pane.
  126.     EraseRect( inFrame, ga_White );
  127.     ::InsetRect( &inFrame, -1, -1 );
  128.     FrameRect( inFrame, ga_5, ga_White, ga_Background );
  129. }
  130.